package com.chima.action;
import java.io.IOException;
import java.util.List;
import org.apache.struts2.ServletActionContext;
import com.chima.domain.Core;
import com.chima.domain.Employees;
import com.chima.service.CoreService;
import com.opensymphony.xwork2.ActionSupport;
import flexjson.JSONSerializer;

public class CoreAction extends ActionSupport{
	
	private int  param;
	private CoreService  coreService;
	private List<Core> cores;
	
	public List<Core> getCores() {
		return cores;
	}
	public void setCores(List<Core> cores) {
		this.cores = cores;
	}
	public CoreService getCoreService() {
		return coreService;
	}
	public void setCoreService(CoreService coreService) {
		this.coreService = coreService;
	}
	public int getParam() {
		return param;
	}
	public void setParam(int param) {
		this.param = param;
	}

	public String  Listcore() throws IOException {
		    Employees  e =(Employees) ServletActionContext.getRequest().getSession().getAttribute("existEmployee");
		    
		    if(param==0){
		    	cores=coreService.findByLevelAndPoerpty(e.getLevel(),param );
		    }else {
		    	cores=coreService.findByLevelAndPoerpty(0,param );
			}
		    JSONSerializer jsonSerializer = new JSONSerializer();
//	        jsonSerializer.include("*.id","*.name");
	        jsonSerializer.exclude("*.class");
	        String resultJson1 = jsonSerializer.serialize(cores);  
	        String jsonString = "{cores:"+resultJson1.toString()+"}";
			ServletActionContext.getResponse().setContentType("text/json;charset=utf-8");
			ServletActionContext.getResponse().getWriter().print(jsonString);
			return NONE;
		
	}
}
